package com.moon.game.command.guest.bag;

import com.moon.game.command.BaseCmd;
import com.moon.game.command.RequestSession;
import com.moon.game.constants.Constants;
import com.moon.game.exception.GException;
import com.moon.game.manager.ItemMG;
import com.moon.game.resource.model.Item;

/**
 * @description 查看通用道具(直接查看资源道具)
 * @author Ranger 作者 E-mail:haozi000005@163.com
 * @version 创建时间：2012-6-16 下午7:48:36
 */
public class ViewCommonItemCmd extends BaseCmd {

	@Override
	protected void runOnce(RequestSession req) throws GException {
		switch (req.getStatus()) {
		case STATU_INIT:
			doInit(req);
			break;
		case STATU_CHECK:
			doCheckSelf(req);
			break;
		case STATU_RETURN:
			doResponse(req);
			break;
		default:
			break;
		}
	}

	@Override
	protected void doResponse(RequestSession req) throws GException {
		String[] ps = req.getClientRequest().getPs();
		if (ps == null) {
			doResponsePsError(req);
			return;
		}
		Integer itemId = Integer.parseInt(ps[0]);
		Item item = ItemMG.instance.getItem(itemId);
		req.setVO("item", item);
		if (ps.length > 1 && Integer.parseInt(ps[1]) == 1) {
			req.setVO("is_goods", true);
		}
		req.setVO("in_city", req.getPlayer().getLocation() == Constants.MAIN_CITY);
		response(req, req.getClientResponse());
	}

}
